Skip to content

[WIP] diagnostics_channel: add meta buil-in channels#61943

Draft
simon-id wants to merge 2 commits intonodejs:mainfrom
simon-id:master
Draft

[WIP] diagnostics_channel: add meta buil-in channels#61943
simon-id wants to merge 2 commits intonodejs:mainfrom
simon-id:master

Conversation

@simon-id
Copy link
Contributor

What

This add DC (diagnostics_channel) built-in events, for DC itself. Just like http, console, or process, have built-in events that can be subscribed to, to monitor code, this make it possible for DC to be monitored through DC.

Why

It appeared that multiple people working with DC channels extensively ended up monkey-patching DC in their test app or test suite, to allow some actions to be logged. Now instead of monkey-patching, they can just listen to these events.

It also allows one to create a kind of "dead-letter queue" DC subscription, that will catch all events that were not delivered:

dc.subscribe('diagnostics_channel.publish', ({ channel, data }) => {
  if (channel.hasSubscribers === false) {
    // handle undelivered event
  }
})

Signed-off-by: simon-id <simon.id@protonmail.com>
@nodejs-github-bot nodejs-github-bot added diagnostics_channel Issues and PRs related to diagnostics channel needs-ci PRs that need a full CI run. labels Feb 22, 2026
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simon-id I think the overall idea is good. Do you plan on finishing this?

@Qard do you mind taking a brief look?

@simon-id
Copy link
Contributor Author

simon-id commented Mar 6, 2026

@BridgeAR I am absolutely finishing this, but I'm still struggling to compile this for some reason. Started with fresh repo and all but can't get any usable compilation error message, so I'm working blind currently. I'll try to get it to compile on a colleague's machine next week 👍

Copy link
Member

@Qard Qard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable. It would be good to see a benchmark of the impact on a publish without subscribers though.

Publish on an inactive channel was intentionally a no-op to have the least possible performance impact when a channel does not have subscribers. With this it has at least an extra hasSubscribers check, and possibly a very noisy publish.

My worry with capturing all publishes everywhere automatically is that if a lot of channels exist, which is encouraged by diagnostics_channel, the performance impact could be substantial. I think I would prefer to have a special channel to publish to whenever a new channel is created. That way you could just listen to that and decide for each channel if you want to attach a subscriber to capture all events from it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics_channel Issues and PRs related to diagnostics channel needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants